import { mainStore } from '@/stores/store'

export const permission = {
    mounted(el, binding) {
        // console.log(binding)
        let {name,type} = binding.value;  
        const useStore = mainStore()
        // console.log(useStore.onlySubDirs)
        let flag = useStore.onlySubDirs.findIndex(item => name === item.COMPONENTNAME)
        // console.log(flag)
        if (flag === -1) {
            el.parentNode?.removeChild(el) 
        }else{
            let flag2 = false
            // console.log(useStore.onlySubDirs[flag])            
            if(type === "delete") flag2 = useStore.onlySubDirs[flag].IS_DEL === 1 ? true : false
            if(type === "add") flag2 = useStore.onlySubDirs[flag].IS_ADD === 1 ? true : false
            if(type === "update") flag2 = useStore.onlySubDirs[flag].IS_UPDATE === 1 ? true : false
            // console.log(flag2)
            if(flag2 === false) el.parentNode?.removeChild(el)
        }
    }
  }
  